package weaver.interfaces.jjy.duss.action;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
/**
 * @program: ecology-9-demo
 * @description: 月度绩效提交接口
 * @author: Dusongsong
 * @create: 2019-12-07
 */
public class WeaHRydjxAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        RecordSet rs2 = new RecordSet();
        RecordSet rs3 = new RecordSet();
        BaseBean baseBean = new BaseBean();
        String requestid = requestInfo.getRequestid();
        baseBean.writeLog("请求ID" + requestid);
        baseBean.writeLog("调用: WeaHRydjxAction");
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        String STATE = "1";
        String message = "";
        rs.executeQuery("select id,gjahr,monat,bmbm,werks,bmsbjbxy,bmsbjbtc, bmsbsk,bmsbzzskj,bmsbjl from " + tablename + " where requestid=?", requestid);
        baseBean.writeLog("select id,gjahr,monat,bmbm,werks,bmsbjbxy,bmsbjbtc, bmsbsk,bmsbzzskj,bmsbjl from " + tablename + " where requestid=?", requestid);
        rs.next();
        String mainid = Util.null2String(rs.getString("id"));//外键
        String GJAHR = Util.null2String(rs.getString("GJAHR"));//年度
        String MONAT = Util.null2String(rs.getString("MONAT"));//月度
        String BMBM = Util.null2String(rs.getString("BMBM"));//部门编码
        String WERKS = Util.null2String(rs.getString("WERKS"));//人事范围编码
        String BMSBJBXY = Util.null2String(rs.getString("BMSBJBXY"));//部门上报加班效益工资
        String BMSBJBTC = Util.null2String(rs.getString("BMSBJBTC"));//部门上报加班提成工资
        String BMSBSK = Util.null2String(rs.getString("BMSBSK"));//部门上报收款提成
        String BMSBZZSKJ = Util.null2String(rs.getString("BMSBZZSKJ"));//部门上报自助收款机提成
        String BMSBJL = Util.null2String(rs.getString("BMSBJL"));//部门上报激励奖金

        if ("8004".equals(WERKS) || "8007".equals(WERKS) || "ZB01".equals(WERKS)) {//更新汇总表
            String updateSQL = "update uf_jxxfhz set bmsbjbxy='" + BMSBJBXY + "' ,bmsbjbtc= '" + BMSBJBTC + "', bmsbsk='" +
                    BMSBSK + "',bmsbzzskj='" + BMSBZZSKJ + "',bmsbjl='" + BMSBJL + "',zt='"+STATE+"',lcid='" + requestid + "' where gjahr='" + GJAHR + "' and monat='" + MONAT + "' and bmbm='" + BMBM + "' and werks='"+WERKS+"'";
            rs.executeUpdate(updateSQL);
            baseBean.writeLog("调用SQL" + updateSQL);
            //更新明细表
            String SQL1 = "select pernr  from " + tablename + "_dt1 where mainid='" + mainid + "'and  gjahr='" + GJAHR + "'and  monat='" + MONAT + "' and bmbm='" + BMBM + "' and werks='"+WERKS+"'";
            rs2.execute(SQL1);
            baseBean.writeLog(SQL1);
            while (rs2.next()) {
                String PERNR = Util.null2String(rs2.getString("PERNR"));//人员编码
                String SQL2 = "select jbxygz,jbtcgz,bmgdsk1,zzskjtc,jljj  from " + tablename + "_dt1 where mainid='" + mainid + "'and  gjahr='" + GJAHR + "'and  monat='" + MONAT + "' and bmbm='" + BMBM + "' and pernr='" + PERNR + "' and werks='"+WERKS+"'";
                rs3.executeQuery(SQL2);
                rs3.next();
                baseBean.writeLog("执行语句：" + SQL2);
                String jbxygz = Util.null2String(rs3.getString("jbxygz"));//加班效益工资
                String jbtcgz = Util.null2String(rs3.getString("jbtcgz"));//加班提成工资
                String bmgdsk1 = Util.null2String(rs3.getString("bmgdsk1"));//收款提成
                String zzskjtc = Util.null2String(rs3.getString("zzskjtc"));//自助收款机提成
                String jljj = Util.null2String(rs3.getString("jljj"));//激励奖金
                String updateSQL1 = "update uf_jxxfmx set jbxygz='" + jbxygz + "',jbtcgz='" + jbtcgz + "',bmgdsk1='" + bmgdsk1 + "', zzskjtc='" + zzskjtc + "',jljj='" + jljj + "' where gjahr='" + GJAHR + "'and  monat='" + MONAT + "' and bmbm='" + BMBM + "' and pernr='" + PERNR + "' and werks='"+WERKS+"'";
                rs3.executeUpdate(updateSQL1);
                baseBean.writeLog(updateSQL1);
                requestInfo.getRequestManager().setMessageid("111100");
                requestInfo.getRequestManager().setMessagecontent(message);
            }
            return Action.SUCCESS;
        } else {
            String updateSQL = "update uf_jxxfhz set bmsbjbxy='" + BMSBJBXY + "' ,bmsbjbtc= '" + BMSBJBTC + "', bmsbsk='" +
                    BMSBSK + "',bmsbzzskj='" + BMSBZZSKJ + "',bmsbjl='" + BMSBJL + "',zt='1'，lcid='" + requestid + "' where gjahr='" + GJAHR + "' and monat='" + MONAT + "' and werks='"+WERKS+"'";
            rs.executeUpdate(updateSQL);
            baseBean.writeLog("调用SQL" + updateSQL);
            //更新明细表
            String SQL1 = "select pernr  from " + tablename + "_dt1 where mainid='" + mainid + "'and  gjahr='" + GJAHR + "'and  monat='" + MONAT + "' and werks='"+WERKS+"'";
            rs2.execute(SQL1);
            baseBean.writeLog(SQL1);
            while (rs2.next()) {
                String PERNR = Util.null2String(rs2.getString("PERNR"));//人员编码
                String SQL2 = "select jbxygz,jbtcgz,bmgdsk1,zzskjtc,jljj  from " + tablename + "_dt1 where mainid='" + mainid + "'and  gjahr='" + GJAHR + "'and  monat='" + MONAT + "' and pernr='" + PERNR + "' and werks='"+WERKS+"'";
                rs3.executeQuery(SQL2);
                rs3.next();
                baseBean.writeLog("执行语句：" + SQL2);
                String jbxygz = Util.null2String(rs3.getString("jbxygz"));//加班效益工资
                String jbtcgz = Util.null2String(rs3.getString("jbtcgz"));//加班提成工资
                String bmgdsk1 = Util.null2String(rs3.getString("bmgdsk1"));//收款提成
                String zzskjtc = Util.null2String(rs3.getString("zzskjtc"));//自助收款机提成
                String jljj = Util.null2String(rs3.getString("jljj"));//激励奖金
                String updateSQL1 = "update uf_jxxfmx set jbxygz='" + jbxygz + "',jbtcgz='" + jbtcgz + "',bmgdsk1='" + bmgdsk1 + "', zzskjtc='" + zzskjtc + "',jljj='" + jljj + "' where gjahr='" + GJAHR + "'and  monat='" + MONAT + "' and pernr='" + PERNR + "' and werks='"+WERKS+"'";
                rs3.executeUpdate(updateSQL1);
                baseBean.writeLog("执行语句："+updateSQL1);
                requestInfo.getRequestManager().setMessageid("111100");
                requestInfo.getRequestManager().setMessagecontent(message);
            }
            return Action.SUCCESS;
        }
    }
}

